from flask import jsonify, request, make_response
import json
from ..common.Token import generate_token
from ..base import base


# from config import DevConfig

# app.config.from_object(DevConfig)
# print(DevConfig)
@base.route('/login', methods=['POST'])
def login():
    params = request.get_data()
    dict1 = json.loads(params)
    username = dict1.get('username')
    password = dict1.get('password')
    print(username, password)
    res = {
        'token': generate_token()
    }

    # res['code'] = 20000
    # data = {}
    # token = {}
    # token['roles'] = ['admin']
    # token['introduction'] = 'I am a super administrator'
    # token['avatar'] = 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif'
    # token['name'] = 'Super Admin'
    # data['token'] = generate_token(g.get('YinDuKey'),3600)
    # res['data'] = data
    res = make_response(res, 200)
    res.headers['Authorization'] = generate_token()
    res.headers['expired'] = (int)(60 * 60 * 1000 / 2)
    return res


@base.route('/getUserInfo')
def getUserInfo():
    # session['no_auth'] = 'false'
    params = request.args.get('user')
    # params = json.loads(params)
    res = {
        "code": 20000,
        "data": {
            'name': '张三'
        }
    }
    return res


@base.route('/logout', methods=['POST'])
def logout():
    return {
        "code": 20000,
        "data": "success"
    }


@base.route('/getpublickey')
def getpublickey():
    # return 响应体, 状态码, 响应头
    return {
        'publickey': "publickey"
    }
